<?php

if (!defined('BASEPATH'))
    exit('Tidak Diperkenankan mengakses langsung');
/* Class  Control : historibayar  * di Buat oleh Diar PHP Generator  *  By Diar */

class ctrcetakkwitansisertifikat extends CI_Controller {

    function __construct() {
        parent::__construct();
    }

    function index($xAwal = 0, $xSearch = '') {
//  $this->load->view('test.php');
        $idpegawai = $this->session->userdata('idpegawai');
        if (empty($idpegawai)) {
            redirect(site_url(), '');
        }
        if ($xAwal <= -1) {
            $xAwal = 0;
        } $this->session->set_userdata('awal', $xAwal);
        $this->createformhistoribayar('0', $xAwal);
    }

    function createformhistoribayar($xidx, $xAwal = 0, $xSearch = '') {
        $this->load->helper('form');
        $this->load->helper('html');
        $this->load->model('modelgetmenu');
        $xAddJs = '<script language="javascript" type="text/javascript" src="' . base_url() . 'resource/js/common/jquery.PrintArea.js"></script>' . "\n" .
                '<script language="javascript" type="text/javascript" src="' . base_url() . 'resource/ajax/ajaxcetakkwitansisertifikat.js"></script>';
        echo $this->modelgetmenu->SetViewAdmin($this->setDetailFormhistoribayar($xidx), '', '', $xAddJs, '');
    }

    function setDetailFormhistoribayar($xidx) {
        $this->load->helper('form');
        $xBufResult = '';
        $xBufResult = '<div id="stylized" class="myform"><h3>Cetak Kartu Dan Kwitansi</h3><div class="garis"></div>' . form_open_multipart('ctrhistoribayar/inserttable', array('id' => 'form', 'name' => 'form'));
        $this->load->helper('common');
        $xBufResult .= '<input type="hidden" name="edidx" id="edidx" value="0" />';
//        $xBufResult .= setForm('edidcustomer', 'idcustomer', form_input(getArrayObj('edidcustomer', '', '100'))) . '<div class="spacer"></div>';
//        $xBufResult .= setForm('edidpaket', 'idpaket', form_input(getArrayObj('edidpaket', '', '100'))) . '<div class="spacer"></div>';
//        $xBufResult .= setForm('edjenisbayar', 'jenisbayar', form_input(getArrayObj('edjenisbayar', '', '100'))) . '<div class="spacer"></div>';
//        $xBufResult .= setForm('edtotal', 'total', form_input(getArrayObj('edtotal', '', '100'))) . '<div class="spacer"></div>';
//        $xBufResult .= setForm('eddate_bayar', 'date_bayar', form_input(getArrayObj('eddate_bayar', '', '100'))) . '<div class="spacer"></div>';
//        $xBufResult .= setForm('edidpegawai', 'idpegawai', form_input(getArrayObj('edidpegawai', '', '100'))) . '<div class="spacer"></div>';
        //$xBufResult .= '<div class="garis"></div>' . form_button('btSimpan', 'simpan', 'onclick="dosimpanhistoribayar();"') . form_button('btNew', 'new', 'onclick="doClearhistoribayar();"') . '<div class="spacer"></div><div id="tabledatacustomer">' . $this->getlistcustomer(0, '') . '</div><div class="spacer"></div>';
        $xBufResult .= '<div id="popcetak"></div>';
        $xBufResult .= '<div class="garis"></div><div class="spacer"></div><div id="tabledatacustomer">' . $this->getlistcustomer(0, '') . '</div><div class="spacer"></div>';
        return $xBufResult;
    }

    function getlisthistoribayar($xAwal, $xSearch) {
        $xLimit = 10;
        $this->load->helper('form');
        $this->load->helper('common');
        $xbufResult = tbaddrow(tbaddcell('idx', '', 'width=10%') .
                tbaddcell('idcustomer', '', 'width=10%') .
                tbaddcell('idpaket', '', 'width=10%') .
                tbaddcell('jenisbayar', '', 'width=10%') .
                tbaddcell('total', '', 'width=10%') .
                tbaddcell('date_bayar', '', 'width=10%') .
                tbaddcell('idpegawai', '', 'width=10%') .
                tbaddcell('Edit/Hapus', 'padding:5px;', 'width:10%;text-align:center;'), '', TRUE);
        $this->load->model('modelhistoribayar');
        $xQuery = $this->modelhistoribayar->getListhistoribayar($xAwal, $xLimit, $xSearch);
        foreach ($xQuery->result() as $row) {
            $xButtonEdit = '<img src="' . base_url() . 'resource/imgbtn/edit.png" alt="Edit Data" onclick = "doedithistoribayar(\'' . $row->idx . '\');" style="border:none;width:20px"/>';
            $xButtonHapus = '<img src="' . base_url() . 'resource/imgbtn/delete_table.png" alt="Hapus Data" onclick = "dohapushistoribayar(\'' . $row->idx . '\',\'' . substr($row->idcustomer, 0, 20) . '\');" style="border:none;">';
            $xbufResult .= tbaddrow(tbaddcell($row->idx) .
                    tbaddcell($row->idcustomer) .
                    tbaddcell($row->idpaket) .
                    tbaddcell($row->jenisbayar) .
                    tbaddcell($row->total) .
                    tbaddcell($row->date_bayar) .
                    tbaddcell($row->idpegawai) .
                    tbaddcell($xButtonEdit . '&nbsp/&nbsp' . $xButtonHapus));
        }
        $xInput = form_input(getArrayObj('edSearch', '', '200'));
        $xButtonSearch = '<img src="' . base_url() . 'resource/imgbtn/b_view.png" alt="Search Data" onclick = "dosearchhistoribayar(0);" style="border:none;width:30px;height:30px;" />';
        $xButtonPrev = '<img src="' . base_url() . 'resource/imgbtn/b_prevpage.png" style="border:none;width:20px;" onclick = "dosearchhistoribayar(' . ($xAwal - $xLimit) . ');"/>';
        $xButtonNext = '<img src="' . base_url() . 'resource/imgbtn/b_nextpage.png" style="border:none;width:20px;" onclick = "dosearchhistoribayar(' . ($xAwal + $xLimit) . ');" />';
        $xbufResult .= tbaddrow(tbaddcell($xInput . $xButtonSearch, '', 'width=10% colspan=2') .
                tbaddcell($xButtonPrev . '&nbsp&nbsp' . $xButtonNext, '', 'width=40% colspan =10'), '', TRUE);
        $xbufResult = tablegrid($xbufResult);
        return '<div class="tabledata"  style="width:100%;left:-12px;">' . $xbufResult . '</div>';
    }

    function editrechistoribayar() {
        $xIdEdit = $_POST['edidx'];
        $this->load->model('modelhistoribayar');
        $row = $this->modelhistoribayar->getDetailhistoribayar($xIdEdit);
        $this->load->helper('json');
        $this->json_data['idx'] = $row->idx;
        $this->json_data['idcustomer'] = $row->idcustomer;
        $this->json_data['idpaket'] = $row->idpaket;
        $this->json_data['jenisbayar'] = $row->jenisbayar;
        $this->json_data['total'] = $row->total;
        $this->json_data['date_bayar'] = $row->date_bayar;
        $this->json_data['idpegawai'] = $row->idpegawai;
        echo json_encode($this->json_data);
    }

    function deletetablehistoribayar() {
        $edidx = $_POST['edidx'];
        $this->load->model('modelhistoribayar');
        $this->modelhistoribayar->setDeletehistoribayar($edidx);
        $this->load->helper('json');
        echo json_encode(null);
    }

    function searchhistoribayar() {
        $xAwal = $_POST['xAwal'];
        $xSearch = $_POST['xSearch'];
        $this->load->helper('json');
        if (($xAwal + 0) == -99) {
            $xAwal = $this->session->userdata('awal', $xAwal);
        }
        if ($xAwal + 0 <= -1) {
            $xAwal = 0;
            $this->session->set_userdata('awal', $xAwal);
        } else {
            $this->session->set_userdata('awal', $xAwal);
        }
        $this->json_data['tabledatahistoribayar'] = $this->getlisthistoribayar($xAwal, $xSearch);
        echo json_encode($this->json_data);
    }

    function simpanhistoribayar() {
        $this->load->helper('json');
        if (!empty($_POST['edidx'])) {
            $xidx = $_POST['edidx'];
        } else {
            $xidx = '0';
        }
        $this->load->helper('common');
        $xidcustomer = $_POST['edidcustomer'];
        $xidpaket = $_POST['edidpaket'];
        $xjenisbayar = $_POST['edjenisbayar'];
        $xtotal = $_POST['edtotal'];
        $xdate_bayar = $_POST['eddate_bayar'];
        $xidpegawai = $_POST['edidpegawai'];
        $this->load->model('modelhistoribayar');
        $idpegawai = $this->session->userdata('idpegawai');
        if (!empty($idpegawai)) {
//            if ($xidx != '0') {
//                $xStr = $this->modelhistoribayar->setUpdatehistoribayar($xidx, $xidcustomer, $xidpaket, $xjenisbayar, $xtotal, date`$xdate_bayar, $xidpegawai);
//            } else {
            $xStr = $this->modelhistoribayar->setInserthistoribayar($xidx, $xidcustomer, $xidpaket, $xjenisbayar, $xtotal, datetomysql($xdate_bayar), $idpegawai);
            //}
        }
        echo json_encode(null);
    }

    ///////////////////////////////////

    function getlistcustomer($xAwal, $xSearch) {
        $xLimit = 20;
        $this->load->helper('form');
        $this->load->helper('common');
        $xbufResult = tbaddrow(tbaddcell('idx', '', 'width=5%') .
                tbaddcell('Name', '', 'width=30%') .
                tbaddcell('Cetak Kwitanasi', 'padding:5px;', 'width:10%;text-align:center;').
                tbaddcell('Cetak Sertifikat', 'padding:5px;', 'width:10%;text-align:center;'), '', TRUE);
        $this->load->model('modelcustomer');
        $this->load->model('modelpaket');
        $this->load->model('modelhistoribayar');
        $xQuery = $this->modelcustomer->getListcustomer($xAwal, $xLimit, $xSearch);
        foreach ($xQuery->result() as $row) {
            $rowlast = $this->modelhistoribayar->getDetailhistoribayarbyid($row->idx);
            $xButtonKwitansi = '<img src="' . base_url() . 'resource/imgbtn/kwitansi.jpg"  alt="Edit Data" onclick = "docetakkwitansi(\'' . $row->idx . '\');" style="border:none;width:40px;height:40px;"/>';
            $xButtonSertifikat = '<img src="' . base_url() . 'resource/imgbtn/sertifikat.jpg"  alt="Edit Data" onclick = "docetaksertifikat(\'' . $row->idx . '\');" style="border:none;width:40px;height:40px;"/>';
//            $xButtonHapus = '<img src="' . base_url() . 'resource/imgbtn/delete_table.png" alt="Hapus Data" onclick = "dohapuscustomer(\'' . $row->idx . '\',\'' . substr($row->title, 0, 20) . '\');" style="border:none;">';
            $xbufResult .= tbaddrow(tbaddcell($row->idx) .
                    tbaddcell($row->title . ' ' . $row->firstname . ' ' . $row->midlename . ' ' . $row->lastname) .                    
                    tbaddcell($xButtonKwitansi) .
                    tbaddcell($xButtonSertifikat));
        }
        $xInput = form_input(getArrayObj('edSearch', '', '200'));
        $xButtonSearch = '<img src="' . base_url() . 'resource/imgbtn/b_view.png" alt="Search Data" onclick = "dosearchcustomer(0);" style="border:none;width:30px;height:30px;" />';
        $xButtonPrev = '<img src="' . base_url() . 'resource/imgbtn/b_prevpage.png" style="border:none;width:20px;" onclick = "dosearchcustomer(' . ($xAwal - $xLimit) . ');"/>';
        $xButtonNext = '<img src="' . base_url() . 'resource/imgbtn/b_nextpage.png" style="border:none;width:20px;" onclick = "dosearchcustomer(' . ($xAwal + $xLimit) . ');" />';
        $xbufResult .= tbaddrow(tbaddcell($xInput . $xButtonSearch, '', 'width=10% colspan=2') .
                tbaddcell($xButtonPrev . '&nbsp&nbsp' . $xButtonNext, '', 'width=40% colspan =10'), '', TRUE);
        $xbufResult = tablegrid($xbufResult);
        return '<div class="tabledata"  style="width:100%;left:-12px;">' . $xbufResult . '</div>';
    }

    function dosethargapaket() {
        $xidpaket = $_POST['edidpaket'];
        $this->load->helper('json');
        $this->load->model('modelpaket');
        $rowpaket = $this->modelpaket->getDetailpaket($xidpaket);
        $this->json_data['hrgpaket'] = $rowpaket->harga;
        echo json_encode($this->json_data);
    }

    function searchcustomer() {
        $xAwal = $_POST['xAwal'];
        $xSearch = $_POST['xSearch'];
        $this->load->helper('json');
        if (($xAwal + 0) == -99) {
            $xAwal = $this->session->userdata('awal', $xAwal);
        }
        if ($xAwal + 0 <= -1) {
            $xAwal = 0;
            $this->session->set_userdata('awal', $xAwal);
        } else {
            $this->session->set_userdata('awal', $xAwal);
        }
        $this->json_data['tabledatacustomer'] = $this->getlistcustomer($xAwal, $xSearch);
        echo json_encode($this->json_data);
    }
    
    function setformsertifikat(){
     $this->load->helper('form');   
     $this->load->helper('common');   
     $xIdCustomer = $_POST['idcustomer'];   
     $this->load->model('modelcustomer');     
     $row = $this->modelcustomer->getDetailcustomer($xIdCustomer);
     $xbaseurl = base_url().'resource/sertifikat/';   
     $xStr   ='<html>
                    <head>
                    <title>Sertifikat</title>
                    <link rel="stylesheet" type="text/css" href="'.$xbaseurl.'css/style.css">
                    </head>
                    <body>
                    <div id="containerkartu">
                    <div id="headerkartu">
                    <div class="logokartu">
                    <img src="'.$xbaseurl.'image/logo.jpg" />
                    </div>
                    <div class="text">
                    <h3>4th INDONESIA CARDIOVASCULAR ANESTHESIA MEETING</h3>
                    <p>Department Anesthesiology and Intensive Therapy</p>
                    <p>Faculty of Medicine Gadjah Mada University - RSUD Dr. Sardjito</p>
                    <p>Jalan Kesehatan No. 1 Yogyakarta, Indonesia</p>
                    </div>
                    </div>
                    <div id="contentkartu">
                    <h1>SERTIFIKAT</h1>
                    <p>In light of the achived ad improved performance</p>
                    <p>'.$row->title . ' ' . $row->firstname . ' ' . $row->midlename . ' ' . $row->lastname.'</p>
                    <p>Port of Panjang has the pleasure to present this award to Branch manager of PT PPN Panurjwan</p>
                    <p>for a remarkable effort and contribution as Top Container Shipping Agent The Biggest Volume - 2014</p>
                    <p>Bandar Lampung, 2013</p>
                    <div class="tandatangan">
                    <span class="nama">Dr. Fahri</span>
                    <img class="stemple" src="'.$xbaseurl.'image/stemple.jpg" />
                    <img class="ttd" src="'.$xbaseurl.'image/ttd.jpg" />
                    </div>
                    </div>
                    <div id="footerkartu">
                    <div class="address">
                    <p>Department Anesthesiology and Intensive Therapy</p>
                    <p>Faculty of Medicine Gadjah Mada University - RSUD Dr. Sardjito</p>
                    <p>Jalan Kesehatan No. 1 Yogyakarta, Indonesia</p>
                    <p>Phone: +62-274-587333 ext. 288, Fax. : +62-274-514495</p>
                    </div>
                    <div class="block"></div>
                    </div>
                    </div>
                    </body>
                    </html>';
        $this->load->helper('json');
        $this->json_data['xpopkartu'] = '<div id="areacetak" style ="width:900px;float:left;position:relative;">'.$xStr.'</div><div id="tombolcetak" style ="width:100%;float:left;position:relative;">'.form_button('btSimpan', 'Cetak', 'onclick="docetakperkartu();"').'</div>';
        echo json_encode($this->json_data);   
    }

    function setformkwitansi(){
     $this->load->helper('form');   
     $this->load->helper('common');   
     $xIdCustomer = $_POST['idcustomer'];   
     $this->load->model('modelcustomer');     
     $this->load->model('modelhistoribayar');     
     $row = $this->modelcustomer->getDetailcustomer($xIdCustomer);
     $this->load->helper('umum');
     $rowbayar = $this->modelhistoribayar->getDetailhistoribayarbyid($xIdCustomer);
     $xbaseurl = base_url().'resource/kwitansi/';   
     
    $xStr ='<html>
                <head>
                <title>Kwitansi</title>
                <link rel="stylesheet" type="text/css" href="'.$xbaseurl.'css/style2.css">
                </head>
                <body>
                <div id="containerkw">
                <div id="headerkw">
                <div class="logokw">
                <img src="'.$xbaseurl.'image/logo.jpg" />
                </div>
                <div class="text">
                <h3>4th INDONESIA CARDIOVASCULAR ANESTHESIA MEETING</h3>
                <p>Department Anesthesiology and Intensive Therapy</p>
                <p>Faculty of Medicine Gadjah Mada University - RSUD Dr. Sardjito</p>
                <p>Jalan Kesehatan No. 1 Yogyakarta, Indonesia</p>
                </div>
                </div>
                <div id="contentkw">
                <h1>KWITANSI</h1>
                <div class="nomor">No. : '.@$rowbayar->idx.'</div>
                <div class="isi">
                <p><span class="lebel">TELAH TERIMA DARI</span><span class="titikdua">&nbsp;:&nbsp;&nbsp;<span>'.$row->title . ' ' . $row->firstname . ' ' . $row->midlename . ' ' . $row->lastname.'</p>
                <p><span class="lebel">BANYAKNYA UANG</span><span class="titikdua">&nbsp;:&nbsp;&nbsp;</span>-'.  terbilang(@$rowbayar->total).' Rupiah-</p>
                <p><span class="lebel">UNTUK PEMBAYARAN</span><span class="titikdua">&nbsp;:&nbsp;&nbsp;</span>'.@$rowbayar->jenisbayar.'</p>
                <p>Terbilang Rp '.number_format(@$rowbayar->total, 2, '.', ',').',-</p>
                </div>
                <div class="tandatangan">
                <span class="tanggal">Yogyakarta, 21 juni 2014</span>
                <img class="stemple" src="'.$xbaseurl.'image/stemple.jpg" />
                <img class="ttd" src="'.$xbaseurl.'image/ttd.jpg" />
                <span class="nama">Dr. Fahri</span>
                </div>
                </div>
                <div id="footerkw">
                <div class="address">
                <p>Department Anesthesiology and Intensive Therapy</p>
                <p>Faculty of Medicine Gadjah Mada University - RSUD Dr. Sardjito</p>
                <p>Jalan Kesehatan No. 1 Yogyakarta, Indonesia</p>
                <p>Phone: +62-274-587333 ext. 288, Fax. : +62-274-514495</p>
                </div>
                <div class="block"></div>
                </div>
                </div>
                </body>
                </html>'; 
        $this->load->helper('json');
        $this->json_data['xpopkartu'] = '<div id="areacetak" style ="width:900px;float:left;position:relative;">'.$xStr.'</div><div id="tombolcetak" style ="width:100%;float:left;position:relative;">'.form_button('btSimpan', 'Cetak', 'onclick="docetakperkartu();"').'</div>';
        echo json_encode($this->json_data);   
    }
}

?>